﻿// JScript 文件
function changeYuE()
{
    var Ckb_YuE=document.getElementById("Ckb_YuE");
    if(Ckb_YuE.checked)
    {
        var yue=document.getElementById("t_yue"); //支付余额
        var KeYuE=document.getElementById("Hid_UserJe");//可用余额
        var P_Amt=document.getElementById("Hid_ShouldPay");//需要支付金额
        var Sp_YuE=document.getElementById("Sp_YuE"); //确定支付的账户余额
        var Ckb_YuE=document.getElementById("Ckb_YuE");
//        if(parseFloat(KeYuE.value)<=0)
//        {
//            alert("可用余额不足");
//            yue.value=0;
//            Ckb_YuE.checked=false;
//            return;
//        }
//        else
//        {
            if(isNaN(yue.value))
            {
                alert("含用非法字符!");
                yue.focus();
                return;
            }
            if(parseFloat(yue.value)<0)
            {
                alert("支付金额不能小于0");
                yue.focus();
                return;
            }
            if(parseFloat(yue.value)>parseFloat(KeYuE.value))
            {
                alert("不能大于可用余额");
                yue.value="0";
                yue.focus();
                return;
            }
            else
            {
                if(parseFloat(yue.value)>parseFloat(P_Amt.value))
                {
                    alert("不能大于待支付金额!");
                    yue.value=P_Amt.value;
                    Sp_YuE.innerHTML=P_Amt.value;
                }
                else
                {
                    Sp_YuE.innerHTML=yue.value;
                }
            }
        }
        calculateFinal();
//    }
}
function calculateFinal()
{
    var P_Amt=document.getElementById("Hid_ShouldPay");//需要支付金额
    var yue=document.getElementById("t_yue"); //确定支付的账户余额
    var FinalJE=document.getElementById("FinalJE");//最终还需要支付金额
    FinalJE.innerHTML=Math.round((parseFloat(P_Amt.value)-parseFloat(yue.value))*1000)/1000;
    var radios=document.getElementsByTagName("input");
    for(var i=0;i<radios.length;i++)
    {
        if(radios[i].type=="radio")
        {
            if(parseFloat(FinalJE.innerHTML)==0)
             {
                radios[i].disabled="disabled";
                if(document.getElementById("Ckb_YuE").checked)
                {
                    var ckb=document.getElementById("Ckb_YuE");                    
                    document.getElementById("Hid_PayMethod").value=ckb.value;
                }
             }
             else
             {
                radios[i].disabled="";
             }             
        }
    }
    
}
function ChoseYuE() //选中余额支付
{   
    var yue=document.getElementById("t_yue"); //支付余额  
    var KeYuE=document.getElementById("Hid_UserJe");//可用余额
    var P_Amt=document.getElementById("Hid_ShouldPay");//需要支付金额             
    var Sp_YuE=document.getElementById("Sp_YuE"); //确定支付的账户余额
    var Ckb_YuE=document.getElementById("Ckb_YuE");
    var radios=document.getElementsByTagName("input");
    var othermethod=document.getElementById("Ckb_FDFK");//其它支付方式
    if(Ckb_YuE.checked)
    {   
       if(parseFloat(KeYuE.value)>=parseFloat(P_Amt.value))
       {
        othermethod.disabled="disabled";
        othermethod.checked=false;
        yue.value=P_Amt.value;
        Sp_YuE.innerHTML=P_Amt.value;
        calculateFinal();
        
            for(var i=0;i<radios.length;i++)
            {
                if(radios[i].type=="radio")
                {
                    radios[i].disabled="disabled";  
                    radios[i].checked=false;                
                }
            }
        }
        else
        {
         alert("可用余额不足!请选择其它的支付方式");
         document.getElementById("Ckb_YuE").checked=false;
         othermethod.disabled="";
         yue.value="0";
         document.getElementById("Sp_YuE").innerHTML="0";
             for(var i=0;i<radios.length;i++)
              {
                if(radios[i].type=="radio")
                {
                    radios[i].disabled="disabled";                
                }
              }
         
        } 
        
    }
    else
    {   
        document.getElementById("Ckb_FDFK").disabled="";
        document.getElementById("Sp_YuE").innerHTML="0";
        document.getElementById("FinalJE").innerHTML=document.getElementById("Hid_ShouldPay").value;  
        document.getElementById("t_yue").value="0";        
        for(var i=0;i<radios.length;i++)
        {
            if(radios[i].type=="radio")
            {
                radios[i].disabled="disabled";
                radios[i].checked=false;
            }
        }      
    }
}
function ChoseBank(obj)//选中银行支付时
{
    var radio=obj.parentElement.children[0];
//    var bank=document.getElementById("BankList");
    var Hid_PayMethod=document.getElementById("Hid_PayMethod");
    var MethodMC=document.getElementById("MethodMC");
//    if(radio.value=="305")
//    {
////        bank.style.display="block";
//        MethodMC.innerHTML="";
//    }
//    else
//    {
//        if(radio.value=="304")
//        {
//           var FinalJE=document.getElementById("FinalJE").innerHTML;//最终还需要支付金额   
//           var KeYuE=document.getElementById("Hid_UserJe").value;//可用余额
//           if(parseFloat(FinalJE)>parseFloat(KeYuE))
//           {
//               alert("可用余额不足!");
//               radio.checked=false;
//               return ;
//           }
//        }
//        bank.style.display="none";
        Hid_PayMethod.value=radio.value;  
        MethodMC.innerHTML=obj.parentElement.children[1].innerHTML; 
//    }    
}
function ChoseFDFK()//选中货到付款
{
   
    var Ckb_YuE=document.getElementById("Ckb_YuE");
    var radios=document.getElementsByTagName("input");
    var fdfk=document.getElementById("Ckb_FDFK");
    var Hid_PayMethod=document.getElementById("Hid_PayMethod");
    var MethodMC=document.getElementById("MethodMC");
    Ckb_YuE.checked=false;
    if(fdfk.checked)
    {   
        document.getElementById("Ckb_FDFK").disabled="";
        document.getElementById("Ckb_YuE").disabled="disabled";
        document.getElementById("Sp_YuE").innerHTML="0";
        document.getElementById("FinalJE").innerHTML=document.getElementById("Hid_ShouldPay").value;  
        document.getElementById("t_yue").value="0";   
        for(var i=0;i<radios.length;i++)
        {        
            if(radios[i].type=="radio")
            {    
                 radios[i].disabled="";
            } 
        } 
        //Hid_PayMethod.value=fdfk.value;  
        //MethodMC.innerHTML="货到付款"; 
    }
    else
    {
        Ckb_YuE.disabled="";
        for(var i=0;i<radios.length;i++)
        {            
            if(radios[i].type=="radio")
            {    
                radios[i].disabled="disabled";
                radios[i].checked=false;
               
            }  
        } 
         Hid_PayMethod.value='';  
         MethodMC.innerHTML='';         
    }
}
function ChooseBank(obj)
{
    var radio=obj.parentElement.children[0];
    var MethodMC=document.getElementById("MethodMC");
    var Hid_PayMethod=document.getElementById("Hid_PayMethod");
    Hid_PayMethod.value=radio.value;  
    MethodMC.innerHTML=obj.parentElement.children[1].innerHTML; 
}
function Next()
{
    var SP_P_Amt=document.getElementById("SP_P_Amt").innerHTML;
    var SP_fare=document.getElementById("SP_fare").innerHTML;
    var SP_ShouldPay=document.getElementById("SP_ShouldPay").innerHTML;
    var Sp_YuE=document.getElementById("Sp_YuE").innerHTML;
    var FinalJE=document.getElementById("FinalJE").innerHTML;
    var MethodMC=document.getElementById("MethodMC").innerHTML;
    var Hid_PayMethod=document.getElementById("Hid_PayMethod").value;
    var SumJF=document.getElementById("SumJF").innerHTML;
    var IsJYK=document.getElementById("Ckb_YuE");
    if(Hid_PayMethod.length<1)
    {
        alert("请选择支付方式!");
        return;
    }
    Mask();
    $j.post("../Handler/OrderPayMethodHandler.ashx", {P_Amt:SP_P_Amt,Fare:SP_fare,ShouldPay:SP_ShouldPay,YuE:Sp_YuE,FinalJE:FinalJE,MethodMC:MethodMC,PayMethod:Hid_PayMethod,SumJF:SumJF,JYK:IsJYK.checked},
            function(data){                          
              if(data)
              {
                 window.location.href="OrderPay.aspx";
              }
              else
              {
                 alert("支付方式提交失败, 请重试!");
                 HidMask();
              }
            }
        );
}
function Mask()
{
    var div_back = document.getElementById("div_background");
    div_back.style.display = "block"; 
    var iframe_back = document.getElementById("iframe_back");
    iframe_back.style.display = "block";     
    var cart = document.getElementById("ShoppingCart");
    cart.style.display = "block";
    cart.style.position = "absolute";
    var bigImg = document.getElementById("Note");
    var pleft = 0;
    var ptop = 0;
   
    var obj = bigImg.offsetParent;
 
    while(obj.tagName != "BODY")
    {
         pleft = pleft + obj.offsetLeft;
         ptop = ptop + obj.offsetTop;
         obj = obj.offsetParent;
    }
    ptop = ptop +50;
    cart.style.left = pleft +200+ "px";
    cart.style.top = ptop +"px";
    cart.style.width = 300 + "px";
    cart.style.backgroundColor  = "#ffffff";
}
function HidMask()
{
    var div_back = document.getElementById("div_background");
    div_back.style.display = "none"; 
    var iframe_back = document.getElementById("iframe_back");
    iframe_back.style.display = "none";   
    var cart = document.getElementById("ShoppingCart");
    cart.style.display = "none";    
}